package cn.chenfeifx.media.controls;

import cn.chenfeifx.media.controls.skin.CFVideoPlayerSkin;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.Control;
import javafx.scene.control.Skin;

import java.util.Objects;

/**
 * 视频组件测试
 */
public class CFVideoPlayer extends Control {

    public CFVideoPlayer() {
        // 饱和度效果测试
//        ColorAdjust adjust = new ColorAdjust();
//        adjust.setSaturation(-1);
//        setEffect(adjust);
        getStyleClass().add("cf-video-player");
    }

    private StringProperty source;

    public final String getSource() {
        return source == null ? "" : source.get();
    }

    public final StringProperty sourceProperty() {
        if (source == null) {
            source = new SimpleStringProperty(this, "source", null);
        }
        return source;
    }

    public final void setSource(String source) {
        sourceProperty().set(source);
    }

    @Override
    public String getUserAgentStylesheet() {
        return Objects.requireNonNull(getClass().getResource("/cn/chenfeifx/media/css/cf-video-player.css")).toExternalForm();
    }

    @Override
    protected Skin<?> createDefaultSkin() {
        return new CFVideoPlayerSkin(this);
    }
}
